package com.kuson.springcloud.controller;

import com.kuson.springcloud.dao.PayMentConfDao;
import com.kuson.springcloud.entities.CommonResult;
import com.kuson.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 读取配置文件中心模块数据
 * 在nacos中创建配置文件。配置文件的创建规则为：服务名称+开发的配置选项（dev/test/prod）+ymal
 */
@RestController
@RefreshScope //自动刷新加载配置中心的数据变化
public class ConfigClientController {
    @Value("${config.info}")
    private String configInfo;
    @Resource
    private PayMentConfDao payMentConfDao;

    @GetMapping("/config/info")
    public String getConfigInfo() {
        return configInfo;
    }

    /**
     * 通过nacos上的数据库连接地址来配置读取数据库表中的数据 ,配置类一定要配置好，
     * @param id
     * @return
     */
    @GetMapping("/config/getById/{id}")
    public CommonResult<Payment> getById(@PathVariable Long id){
        return new CommonResult<Payment>(200,"成功",payMentConfDao.getPaymentByIds(id));
    }
}
